<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加商户</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
	<style>
		.layui-form-label{width:120px!important}
	</style>
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加商户{else}<i class="fa fa-pencil"></i> 编辑商户{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					{if $info['status']==2}<blockquote class="layui-elem-quote" style="color:red">商户未审核通过，驳回原因：{$info.reason}</blockquote>{/if}
					<div class="layui-form">
						<input type="hidden" name="info[id]" value="{$info.id}"/>
						<input type="hidden" name="uinfo[id]" value="{$uinfo['id']}">
						
						<div class="layui-form-item">
							<label class="layui-form-label">商户分类：</label>
							<div class="layui-input-inline" style="width:300px">
								<select name="info[cid]" xm-select="selectCid" xm-select-max="500" xm-select-search>
								<option value="">--请选择--</option>
								{foreach $clist as $cv}
									<option value="{$cv['id']}" {if in_array($cv['id'],$info['cid'])}selected{/if}>{$cv['name']}</option>
								{/foreach}
								</select>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">商户名称：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[name]" lay-verify="required" lay-verType="tips" class="layui-input" value="{$info.name}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">登录账号：</label>
							<div class="layui-input-inline">
								<input type="text" name="uinfo[un]" value="{$uinfo['un']}" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">登录密码：</label>
							<div class="layui-input-inline">
								<input type="text" class="layui-input" autocomplete="off" name="uinfo[pwd]" value="" {if $uinfo['id']} placeholder="留空表示不修改密码"{else} lay-verify="required" lay-verType="tips"{/if}>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">抽成费率：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[feepercent]" class="layui-input" value="{$info.feepercent}">
							</div>
							<div class="layui-form-mid" style="margin-left:10px;">%，平台收取的佣金比例，如设置10%，平台抽成10%，商家得90%</div>
						</div>
						
						
						{if $set['wxfw_status'] == 1}
						<div class="layui-form-item">
							<label class="layui-form-label">子商户号收款：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="radio" name="info[wxpayst]" value="0" title="关闭" {if !$info['id'] || $info['wxpayst']==0}checked{/if} lay-filter="wxpayst"/>
								<input type="radio" name="info[wxpayst]" value="1" title="开启" {if $info['wxpayst']==1}checked{/if} lay-filter="wxpayst"/>
							</div>
							<div class="layui-form-mid layui-word-aux">开启后可设置子商户号独立收款结算</div>
						</div>
						<div class="layui-form-item" {if !$info['id'] || $info['wxpayst']==0}style="display:none"{/if} id="wxpayst_div">
							<label class="layui-form-label">子商户号：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[wxpay_submchid]" class="layui-input" value="{$info.wxpay_submchid}">
							</div>
							<div class="layui-form-mid" style="margin-left:10px;">在微信支付服务商后台申请的商户号</div>
						</div>
						{/if}
						
						<div class="layui-form-item">
							<label class="layui-form-label">联系人：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[linkman]" class="layui-input" value="{$info.linkman}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">联系电话：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[linktel]" class="layui-input" value="{$info.linktel}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">客服电话：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[tel]" class="layui-input" value="{$info.tel}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">客服链接：</label>
							<div class="layui-input-inline" style="width:300px">
								<input type="text" name="info[kfurl]" value="{$info.kfurl}" class="layui-input"/>
							</div>
							<div class="layui-form-mid layui-word-aux">商品详情页客服链接，不填写则使用商城内部客服系统</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">商家主图：</label>
							<input type="hidden" name="info[logo]" id="logo" lay-verType="tips" class="layui-input" value="{$info.logo}">
							<button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="logo" upload-preview="logoPreview" onclick="uploader(this)">上传图片</button>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
							<div id="logoPreview" style="float:left;padding-top:10px;padding-left:150px;clear: both;">
								<div class="layui-imgbox" style="width:100px;">
									<div class="layui-imgbox-img"><a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().find('img').attr('src','');getpicsval('logo','logoPreview')" title="删除"><i class="layui-icon layui-icon-close-fill"></i></a><img src="{$info.logo}"/></div>
								</div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">商家照片：</label>
							<input type="hidden" name="info[pics]" value="{$info['pics']}" id="pics">
							<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="pics" upload-preview="picList" >批量上传</button>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：600*340像素</div>
							<div id="picList" style="float:left;padding-top:10px;padding-left:150px;clear: both;">
								{if $info['pics']}
								{php}$pics = explode(',',$info['pics']);{/php}
								{foreach $pics as $pic}
								<div class="layui-imgbox">
									<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('pics','picList')" title="删除"><i class="layui-icon layui-icon-close-fill"></i></a>
									<span class="layui-imgbox-img"><img src="{$pic}" onclick="previewImg('{$pic}')"></span>
								</div>
								{/foreach}{/if}
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">商家描述：</label>
							<div class="layui-input-inline" style="width:700px">
								<input type="text" name="info[desc]" class="layui-input" value="{$info.desc}">
							</div>
						</div>
						
						<!-- <div class="layui-form-item">
							<label class="layui-form-label">服务标签：</label>
							<div class="layui-input-inline" style="width:400px">
								<input type="text" name="info[fuwupoint]" class="layui-input" value="{$info.fuwupoint}">
							</div>
							<div class="layui-form-mid layui-word-aux">多个用空格隔开,如: 7天退换 48小时发货 假一赔十</div>
						</div> -->
						<div class="layui-form-item">
							<label class="layui-form-label">商家简介：</label>
							<div class="layui-input-inline" style="width:500px;">
								<script id="content" name="info[content]" type="text/plain" style="width:100%;height:500px">{$info.content}</script>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">商家地址：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="text" id="address" name="info[address]" class="layui-input" value="{$info.address}">
							</div>
							<button class="layui-btn layui-btn-primary" id="searchbtn">搜索</button>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"></label>
							<div id="l-map" style="width:600px;height:350px">地图加载中...</div>
							<div style="margin-left:150px;margin-top:10px">
								<div class="layui-input-inline" style="width:200px">
									<input type="text" name="info[longitude]" id="mapjd" class="layui-input" value="{$info.longitude|default='116.39782905578613'}"/>
								</div>
								<div class="layui-input-inline" style="width:200px">
									<input type="text" name="info[latitude]" id="mapwd" class="layui-input" value="{$info.latitude|default='39.90358020251377'}"/>
								</div>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label">证明材料：</label>
							<input type="hidden" name="info[zhengming]" value="{$info['zhengming']}" id="zhengming">
							<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="zhengming" upload-preview="zhengmingList" >批量上传</button>
							<div id="zhengmingList" style="float:left;padding-top:10px;padding-left:150px;clear: both;">
								{if $info['zhengming']}
								{php}$pics = explode(',',$info['zhengming']);{/php}
								{foreach $pics as $pic}
								<div class="layui-imgbox">
									<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('zhengming','zhengmingList')" title="删除"><i class="layui-icon layui-icon-close-fill"></i></a>
									<span class="layui-imgbox-img"><img src="{$pic}" onclick="previewImg('{$pic}')"></span>
								</div>
								{/foreach}{/if}
							</div>
						</div>
						
						<!-- <div class="layui-form-item">
							<label class="layui-form-label">微信号：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[weixin]" class="layui-input" value="{$info.weixin}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">支付宝：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[aliaccount]" class="layui-input" value="{$info.aliaccount}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">开户行：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[bankname]" class="layui-input" value="{$info.bankname}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">持卡人：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[bankcarduser]" class="layui-input" value="{$info.bankcarduser}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">银行卡号：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[bankcardnum]" class="layui-input" value="{$info.bankcardnum}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">消费人数：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[sales]" value="{$info.sales|default=0}" class="layui-input">
							</div>
						</div> -->
						<div class="layui-form-item">
							<label class="layui-form-label">序号：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[sort]" value="{$info.sort|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">用于排序,越大越靠前</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">状态：</label>
							<div class="layui-input-inline" style="width:310px">
								<input type="radio" name="info[status]" value="0" title="待审核" {if $info['id'] && $info['status']==0}checked{/if} lay-filter="changest">
								<input type="radio" name="info[status]" value="1" title="已通过" {if !$info['id'] || $info['status']==1}checked{/if} lay-filter="changest">
								<input type="radio" name="info[status]" value="2" title="已驳回" {if $info['id'] && $info['status']==2}checked{/if} lay-filter="changest">
							</div>
						</div>
						<div id="changestset" {if $info['status']!=2}style="display:none"{/if}>
							<div class="layui-form-item">
								<label class="layui-form-label">驳回原因：</label>
								<div class="layui-input-inline" style="width:310px">
									<input type="text" name="info[reason]" value="{$info['reason']}" class="layui-input"/>
								</div>
							</div>
						</div>
						
<!--						<div class="layui-form-item">-->
<!--							<label class="layui-form-label">模块权限：</label>-->
<!--							<div class="layui-input-inline">-->
<!--								<input type="radio" name="uinfo[auth_type]" value="1" title="所有" {if !$uinfo['id'] || $uinfo['auth_type']==1}checked{/if} lay-filter="auth_type">-->
<!--								<input type="radio" name="uinfo[auth_type]" value="0" title="选择" {if $uinfo['id'] && $uinfo['auth_type']==0}checked{/if} lay-filter="auth_type">-->
<!--							</div>-->
<!--						</div>-->
<!--						<div class="layui-form-item" id="authdataset" style="{if !$uinfo['id'] || $uinfo['auth_type']==1}display:none{/if}"></div>-->
		  					<input type="hidden" name="uinfo[auth_type]" value="0">
							{include file="public/user_auth"/}


						<div class="layui-form-item">
							<label class="layui-form-label"></label>
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
							</div>
						</div>
					</div>
				</div>
      </div>
    </div>
  </div>
	{include file="public/js"/}
	<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=ABLBZ-4BIKU-GFTVB-BK7IK-OLQ35-QCBFF"></script>
	<script>
	
	layui.form.on('radio(wxpayst)',function(data){
		if(data.value == '1'){
			$('#wxpayst_div').show();
		}else{
			$('#wxpayst_div').hide();
		}
	})

	layui.form.on('radio(auth_type)', function(data){
		if(data.value == '0'){
			$('#authdataset').show();
		}else{
			$('#authdataset').hide();
		}
	})
	layui.form.on('checkbox(checkall_all)',function(data){
		if(data.elem.checked){
			$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',true);
		}else{
			$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',false);
		}
		layui.form.render('checkbox'); 
	})
	layui.form.on('checkbox(checkall)',function(data){
		if(data.elem.checked){
			$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',true);
		}else{
			$(data.elem).parent().parent().find('input[type=checkbox]').prop('checked',false);
		}
		layui.form.render('checkbox'); 
	})
	layui.form.on('radio(changest)', function(data){
		if(data.value == '2'){
			$('#changestset').show();
		}else{
			$('#changestset').hide();
		}
	})
	var ueditor = UE.getEditor('content');
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		field['info[content]'] = ueditor.getContent();
		//console.log(field);return;
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.close(parent.layer.getFrameIndex(window.name));
					parent.tableIns.reload()
				},1000)
			}
		})
	})
  </script>
	<script>
	
	var searchService, map,markers = [],marker = null;
	var jd = $('#mapjd').val();
	var wd = $('#mapwd').val();
	window.onload=function(){
		function init(){
			var center = new qq.maps.LatLng(wd,jd);
			var map = new qq.maps.Map(document.getElementById("l-map"), {
				center: center,      // 地图的中心地理坐标。
				zoom:15              // 地图的中心地理坐标。
			});	
			var marker = new qq.maps.Marker({ position:center, map: map});
			markers.push(marker);
			 //绑定单击事件添加参数
			qq.maps.event.addListener(map, 'click', function(event) {
				clearOverlays(markers);
				$("#mapjd").val(event.latLng.getLng());
				$("#mapwd").val(event.latLng.getLat());
				var marker = new qq.maps.Marker({ position: new qq.maps.LatLng(event.latLng.getLat(), event.latLng.getLng()) , map: map
				});
				markers.push(marker);
			});
			//设置Poi检索服务，用于本地检索、周边检索
			searchService = new qq.maps.SearchService({
				//设置搜索范围为北京
				location: center.lat+"," +center.lng,
				//设置搜索页码为1
				pageIndex: 1,
				//设置每页的结果数为5
				pageCapacity: 5,
				//设置展现查询结构到infoDIV上
				// panel: document.getElementById('infoDiv'),
				//设置动扩大检索区域。默认值true，会自动检索指定城市以外区域。
				autoExtend: true,
				//检索成功的回调函数
				complete: function(results) {
					//设置回调函数参数
					var pois = results.detail.pois;
					var infoWin = new qq.maps.InfoWindow({
						map: map
					});
					var latlngBounds = new qq.maps.LatLngBounds();
					for (var i = 0, l = pois.length; i < l; i++) {
						var poi = pois[i];
						//扩展边界范围，用来包含搜索到的Poi点
						latlngBounds.extend(poi.latLng);
						(function(n) {
							var marker = new qq.maps.Marker({
								map: map
							});
							marker.setPosition(pois[n].latLng);
							marker.setTitle(i + 1);
							markers.push(marker);
							qq.maps.event.addListener(marker, 'click', function() {
								$("#mapjd").val(pois[n].latLng.lng);
								$("#mapwd").val(pois[n].latLng.lat);
								infoWin.setPosition(pois[n].latLng);
							});
						})(i);
					}
					//调整地图视野
					map.fitBounds(latlngBounds);
				},
				//若服务请求失败，则运行以下函数
				error: function() {
					dialog("请先搜索省市区再搜索详细地址");
				}
			});
		}
		init();
	}
	//清除地图上的marker
    function clearOverlays(overlays) {
        var overlay;
        while (overlay = overlays.pop()) {
            overlay.setMap(null);
        }
    }
	$("#searchbtn").click(function(){
		var address = $("#address").val();
		if(address == ""){
			dialog("请输地址！");
			return ;
		}
		 clearOverlays(markers);
		//根据输入的关键字在搜索范围内检索
    searchService.search(address);
	});
	function previewImg(url){
		layer.open({type:1,area:'500px',content:'<div style="margin:auto auto;text-align:center"><img src="'+url+'" style="max-width:100%;max-height:100%"/></div>',title:false,shadeClose:true})
	}
	</script>
</body>
</html>